/**
 * 系统平台
 * moonvip_admin
 * com.tz.web.store
 * StoreController.java
 * 创建人:小胡
 * 时间：2016年12月20日 10:58:20
 *
 */
package com.tz.web.store;

import com.tz.auth.AuthPassport;
import com.tz.bean.Store;
import com.tz.bean.TzParams;
import com.tz.service.store.IStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;

/**
 * 门店管理web
 * StoreController
 * 创建人:小胡
 * 时间：2016年12月20日 10:58:20
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("/admin/store")
public class StoreController {
	
	@Autowired
	private IStoreService storeService;

	/*列表查询*/
	@AuthPassport
	@RequestMapping("/list")
	public String list(TzParams params){
		return "store/list";
	}

    /*模板页面*/
	@RequestMapping("/template")
	public String template(TzParams params ,Model model){
		params.setDeleteCode("001");
		model.addAttribute("datas", storeService.findStores(params));
		model.addAttribute("itemCount", storeService.count(params));
		return "store/template";
	}


	@AuthPassport
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String delete(TzParams params){
		storeService.delete(params);
		return "success";
	}

	@AuthPassport
	@RequestMapping("/add")
    public String add(TzParams params){
		return "store/add";
   }

	@AuthPassport
	@RequestMapping(value = "/edit/{id}" ,method = RequestMethod.GET)
	public String edit(@PathVariable("id") Integer id , Model model){
		HashMap<String ,Object> store = storeService.getStore(id);
		model.addAttribute("store",store);
		return "store/edit";
	}


	@ResponseBody
	@RequestMapping(value = "/save",method=RequestMethod.POST)
	public int save(Store store){
		int n = storeService.save(store);
		return n;
	}


	@ResponseBody
	@RequestMapping(value="/updateStore",method= RequestMethod.POST)
	public int updateStore(Store store){
		store.setUpdateTime(new Date());
		int n = storeService.update(store);
		return n;
	}

	@ResponseBody
	@RequestMapping(value="/update",method= RequestMethod.POST)
	public String update(Store store){
		store.setUpdateTime(new Date());
		storeService.update(store);
		return "success";
	}

}
